package com.example.socket.server;

import com.example.socket.model.DataPackage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author xiaocg
 */
public class MyMessageEncode extends MessageToByteEncoder<DataPackage> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, DataPackage dataPackage, ByteBuf byteBuf) throws Exception {
        byteBuf.writeBytes(dataPackage.getTag());
        byteBuf.writeInt(dataPackage.getType());
        byteBuf.writeInt(dataPackage.getLength());
        byteBuf.writeBytes(dataPackage.getValue());
    }
}
